%%%-------------------------------------------------------------------
%%% @author admin
%%% @copyright (C) 2022, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 20. 六月 2022 17:37
%%%-------------------------------------------------------------------
-module(account_sl).
-author("admin").

-include("account.hrl").

%% API
-export([
    save/1,
    load/1,
    feilds/0
]).


save(#account{
    account_id = AccountId,
    player_list = PlayerList
}) ->
    Data =
        [
            <<"account_id">>,    AccountId
            ,<<"player_list">>,    PlayerList
        ],
    {ok, Data};
save(_) ->
    {error, bad_record}.


load(Data) ->
    load(Data, #account{}).
load([], Player) -> {ok, Player};
load([{<<"account_id">>, AccountId}|Data], Account = #account{}) ->
    load(Data, Account#account{account_id = AccountId});
load([{<<"player_list">>, PlayerList}|Data], Account = #account{}) ->
    load(Data, Account#account{player_list = PlayerList});
load([_ | Data], Account) ->
    load(Data, Account).

feilds() ->
    [account_id, player_list].